package com.cml.getway.core.context;


import com.cml.getway.common.config.Rule;
import io.netty.channel.ChannelHandlerContext;

import java.util.function.Consumer;

/**
 * 姓名：陈茂林
 * 时间：2024/1/8
 * 描述：
 */
public interface Context {
    //	一个请求正在执行过程中
    int RUNNING = -1;

    // 	写回响应标记, 标记当前Context/请求需要写回
    int WRITTEN = 0;

    //	当写回成功后, 设置该标记：ctx.writeAndFlush(response);
    int COMPLETED = 1;

    //	表示整个网关请求完毕, 彻底结束
    int TERMINATED = 2;

    void runned();

    void writtened();

    void completed();

    void terminated();

    /*************** -- 判断网关的状态系 -- ********************/

    boolean isRunning();

    boolean isWrittened();

    boolean isCompleted();

    boolean isTerminated();

    String getProtocol();

    Rule getRule();

    Object getRequest();

    Object getResponse();

    void setResponse(Object response);

    void setThrowable(Throwable throwable);

    Throwable getThrowable();

    <T> T getAttribute(AttributeKey<T> key);

    <T> T putAttribute(AttributeKey<T> key, T value);

    ChannelHandlerContext getNettyCtx();

    boolean isKeepAlive();

    void releaseRequest();

    void invokeCompletedCallback();

    void completedCallback(Consumer<Context> consumer);

    long getSRTime();

    void setSRTime(long sRTime);

    long getSSTime();

    void setSSTime(long sSTime);

    long getRSTime();

    void setRSTime(long rSTime);

    long getRRTime();

    void setRRTime(long rRTime);
}
